//
//  WBNavigationController.swift
//  weibo
//
//  Created by yanghong on 15/12/5.
//  Copyright © 2015年 杨鸿. All rights reserved.
//

import UIKit

class WBNavigationController: UINavigationController,UIGestureRecognizerDelegate {
    
    override func viewDidLoad() {
        
        super.viewDidLoad()
        // 解决按住根控制器边缘向右滑动,再次push新控制器 ,push失败的BUG
        self.interactivePopGestureRecognizer?.delegate = self
    }

    
    override func pushViewController(viewController: UIViewController, animated: Bool) {
        
        if childViewControllers.count > 0 {
            
            var title = "返回"
            
            if childViewControllers.count == 1 {
                
                title = childViewControllers.first!.title ?? title
                
            }
            viewController.hidesBottomBarWhenPushed = true
            
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(imgName: "navigationbar_back_withtext", title: title, target: self, action: "back")
            
        }
        
        super.pushViewController(viewController, animated: true)
        
    }
    
    @objc private func back() {
        
        popViewControllerAnimated(true)
        
    }
    
    func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {
        
        return childViewControllers.count != 1
        
    }
    
}
